home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / xlib / yakems11 / emscheck.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-04  |  1.9 KB  |  70 lines

  1. /*
  2.  * Emstest.c -- EMS Table Routines Test Pgm
  3.  */
  4. #include "stddefs.h"
  5. #include "yaklist.h"
  6. #include "yakems.h"
  7. #include <iostream.h>
  8. #include <dos.h>
  9. #include <stdlib.h>
  10. #include <conio.h>
  11. void main()
  12. {
  13.     randomize();
  14.     if (!emsBlock::wInit())
  15.     {
  16.         cout << "sorry, your machine does not have EMS enabled.\n";
  17.         return;
  18.     }
  19. //    emsData testData1;
  20. //    testData1.pbAllocate(55);
  21. //  testData1.pbAllocate(33);
  22.     emsData *pDChunk1, *pDChunk2, *pDChunk3, *pDChunk4;
  23.     pDChunk1 = new emsData;
  24.     pDChunk2 = new emsData;
  25.     pDChunk3 = new emsData;
  26.     pDChunk4 = new emsData;
  27.     cout << "\n\nEMSCheck-- short demo of EMS routines; press a key between sections.\n";
  28.     cout << "First allocate three blocks of EMS memory.\n";
  29.     getch();
  30.     pDChunk1->pbAllocate(0);
  31.     pDChunk2->pbAllocate(0);
  32.     pDChunk3->pbAllocate(0);
  33.     emsBlock::showBlockStatus();
  34.     cout << "\n\nNow delete the second block:\n";
  35.     getch();
  36.     delete pDChunk2;
  37.     emsBlock::showBlockStatus();
  38.     cout << "\n\nNow we'll allocate a third block that fits between the two:\n";
  39.     getch();
  40.     pDChunk4->pbAllocate(5);
  41.     emsBlock::showBlockStatus();
  42.     cout << "\n\nAnd now we'll defragment the EMS to show it's compacted:\n";
  43.     getch();
  44.     emsBlock::defragmentAllEMS();
  45.     emsBlock::showBlockStatus();
  46.     cout << "\n\nAnd now an interesting test-- we'll allocate blocks of data\n";
  47.     cout << "until there's no more room in EMS using random allocation:";
  48.     getch();
  49.     long sumOfMem = 0;
  50.     emsData * pDNewData = NULL;
  51. //    emsData testData;
  52. //    testData.pbAllocate(55);
  53.     emsBlock::showBlockStatus();
  54.     getch();
  55.     int iGo = 2;
  56.     while(iGo)
  57.     {
  58.         pDNewData = new emsData;
  59.         pDNewData->pbAllocate(random(32000) * 2);
  60.         sumOfMem += pDNewData->wSize;
  61.         cout << pDNewData->wSize << " \tbytes allocated with handle " << pDNewData->iHandle << "\n";
  62.         if (pDNewData->iHandle == 0)
  63.             --iGo;
  64.     }
  65.     emsBlock::showBlockStatus();
  66.     cout << "Total memory allocated: " << sumOfMem << "\n";
  67. }
  68.  
  69.  
  70.